home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / tcl / tcl70b2.lha / tcl7.0b2 / tests / if.test < prev    next >
Text File  |  1993-02-06  |  5KB  |  163 lines

  1. # Commands covered:  if
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright (c) 1991-1993 The Regents of the University of California.
  8. # All rights reserved.
  9. #
  10. # Permission is hereby granted, without written agreement and without
  11. # license or royalty fees, to use, copy, modify, and distribute this
  12. # software and its documentation for any purpose, provided that the
  13. # above copyright notice and the following two paragraphs appear in
  14. # all copies of this software.
  15. #
  16. # IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  17. # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  18. # OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  19. # CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20. #
  21. # THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  22. # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  23. # AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  24. # ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  25. # PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  26. #
  27. # $Header: /user6/ouster/tcl/tests/RCS/if.test,v 1.5 93/02/06 15:54:17 ouster Exp $ (Berkeley)
  28.  
  29. if {[string compare test [info procs test]] == 1} then {source defs}
  30.  
  31. test if-1.1 {taking proper branch} {
  32.     set a {}
  33.     if 0 {set a 1} else {set a 2}
  34.     set a
  35. } 2
  36. test if-1.2 {taking proper branch} {
  37.     set a {}
  38.     if 1 {set a 1} else {set a 2}
  39.     set a
  40. } 1
  41. test if-1.3 {taking proper branch} {
  42.     set a {}
  43.     if 1<2 {set a 1}
  44.     set a
  45. } 1
  46. test if-1.4 {taking proper branch} {
  47.     set a {}
  48.     if 1>2 {set a 1}
  49.     set a
  50. } {}
  51. test if-1.5 {taking proper branch} {
  52.     set a {}
  53.     if 0 {set a 1} else {}
  54.     set a
  55. } {}
  56. test if-1.5 {taking proper branch} {
  57.     set a {}
  58.     if 0 {set a 1} elseif 1 {set a 2} elseif 1 {set a 3} else {set a 4}
  59.     set a
  60. } {2}
  61. test if-1.6 {taking proper branch} {
  62.     set a {}
  63.     if 0 {set a 1} elseif 0 {set a 2} elseif 1 {set a 3} else {set a 4}
  64.     set a
  65. } {3}
  66. test if-1.7 {taking proper branch} {
  67.     set a {}
  68.     if 0 {set a 1} elseif 0 {set a 2} elseif 0 {set a 3} else {set a 4}
  69.     set a
  70. } {4}
  71.  
  72.  
  73. test if-2.1 {optional then-else args} {
  74.     set a 44
  75.     if 0 then {set a 1} elseif 0 then {set a 3} else {set a 2}
  76.     set a
  77. } 2
  78. test if-2.2 {optional then-else args} {
  79.     set a 44
  80.     if 1 then {set a 1} else {set a 2}
  81.     set a
  82. } 1
  83. test if-2.3 {optional then-else args} {
  84.     set a 44
  85.     if 0 {set a 1} else {set a 2}
  86.     set a
  87. } 2
  88. test if-2.4 {optional then-else args} {
  89.     set a 44
  90.     if 1 {set a 1} else {set a 2}
  91.     set a
  92. } 1
  93. test if-2.5 {optional then-else args} {
  94.     set a 44
  95.     if 0 then {set a 1} {set a 2}
  96.     set a
  97. } 2
  98. test if-2.6 {optional then-else args} {
  99.     set a 44
  100.     if 1 then {set a 1} {set a 2}
  101.     set a
  102. } 1
  103. test if-2.7 {optional then-else args} {
  104.     set a 44
  105.     if 0 then {set a 1} else {set a 2}
  106.     set a
  107. } 2
  108. test if-2.8 {optional then-else args} {
  109.     set a 44
  110.     if 0 then {set a 1} elseif 0 {set a 2} elseif 0 {set a 3} {set a 4}
  111.     set a
  112. } 4
  113.  
  114. test if-3.1 {return value} {
  115.     if 1 then {set a 22; concat abc}
  116. } abc
  117. test if-3.2 {return value} {
  118.     if 0 then {set a 22; concat abc} elseif 1 {concat def} {concat ghi}
  119. } def
  120. test if-3.3 {return value} {
  121.     if 0 then {set a 22; concat abc} else {concat def}
  122. } def
  123. test if-3.4 {return value} {
  124.     if 0 then {set a 22; concat abc}
  125. } {}
  126. test if-3.5 {return value} {
  127.     if 0 then {set a 22; concat abc} elseif 0 {concat def}
  128. } {}
  129.  
  130. test if-4.1 {error conditions} {
  131.     list [catch {if} msg] $msg
  132. } {1 {wrong # args: no expression after "if" argument}}
  133. test if-4.2 {error conditions} {
  134.     list [catch {if {[error "error in condition"]}} msg] $msg
  135. } {1 {error in condition}}
  136. test if-4.3 {error conditions} {
  137.     list [catch {if 2} msg] $msg
  138. } {1 {wrong # args: no script following "2" argument}}
  139. test if-4.4 {error conditions} {
  140.     list [catch {if 2 then} msg] $msg
  141. } {1 {wrong # args: no script following "then" argument}}
  142. test if-4.5 {error conditions} {
  143.     list [catch {if 2 the} msg] $msg
  144. } {1 {invalid command name: "the"}}
  145. test if-4.6 {error conditions} {
  146.     list [catch {if 2 then {[error "error in then clause"]}} msg] $msg
  147. } {1 {error in then clause}}
  148. test if-4.7 {error conditions} {
  149.     list [catch {if 0 then foo elseif} msg] $msg
  150. } {1 {wrong # args: no expression after "elseif" argument}}
  151. test if-4.8 {error conditions} {
  152.     list [catch {if 0 then foo elsei} msg] $msg
  153. } {1 {invalid command name: "elsei"}}
  154. test if-4.9 {error conditions} {
  155.     list [catch {if 0 then foo elseif 0 bar else} msg] $msg
  156. } {1 {wrong # args: no script following "else" argument}}
  157. test if-4.10 {error conditions} {
  158.     list [catch {if 0 then foo elseif 0 bar els} msg] $msg
  159. } {1 {invalid command name: "els"}}
  160. test if-4.11 {error conditions} {
  161.     list [catch {if 0 then foo elseif 0 bar else {[error "error in else clause"]}} msg] $msg
  162. } {1 {error in else clause}}
  163.